#ifndef UIFILE_H_
#define UIFILE_H_

#include "File.h"
#include "Window.h"
#include "UIElement.h"
#include "UILabel.h"
#include "UIButton.h"
#include "StretchyLayout.h"
#include <map>

namespace Lame3d
{
	class UIFile
	{
		public:
			class Entry
			{
				public:
					~Entry();
					
					Entry& operator=(const std::string &v);
					Entry& operator=(float f);
					Entry& operator=(int i);
					
					const std::string& String() const;
					int Int() const;
					float Float() const;
					
					const std::string& Key() const;
					const std::string& Value() const;
					
				protected:
					Entry(const std::string &line);
					
					std::string key;
					std::string value;
				
				friend class UIFile;
			};
		
			UIFile(const File &f);
			~UIFile();
			
			Window* GenerateWindow() const;
			
		protected:
			class ParseNode
			{
				public:
					~ParseNode();
					
					const Entry* GetEntry(const std::string &s) const;
					std::map<std::string, Entry*>::const_iterator EntriesBegin() const;
					std::map<std::string, Entry*>::const_iterator EntriesEnd() const;
					
					const ParseNode* GetNode(const std::string &s) const;
					std::map<std::string, ParseNode*>::const_iterator NodesBegin() const;
					std::map<std::string, ParseNode*>::const_iterator NodesEnd() const;
					
					const std::string& Type() const;
					const std::string& Name() const;
					
					UILabel* BuildLabel();
					UIButton* BuildButton();
					UITextEntry* BuildTextEntry();
					
					StretchyLayout::Properties* BuildStretchyProps();
					
				protected:
					ParseNode(const std::string& firstLine);
					
					std::map<std::string, Entry*> entries;
					std::map<std::string, ParseNode*> subNodes;
					
					std::string type;
					std::string name;
					
					void buildEvents(UIElement *e);
					
				friend class UIFile; 
			};
			
			ParseNode *rootNode;
				
			File file;
			
			void buildTree();
			int numTabs(const std::string &s); 
	};
}

#endif /*UIFILE_H_*/
